<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="5" :sm="12">
            <a-form-item label="商家名称">
              <!--<a-input placeholder="请输入账号查询" v-model="queryParam.username"></a-input>-->
              <j-input placeholder="输入商家名称" v-model="queryParam.username"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="5" :sm="12">
            <a-form-item label="设备型号">
              <!--<a-input placeholder="请输入账号查询" v-model="queryParam.username"></a-input>-->
              <j-input placeholder="输入设备型号" v-model="queryParam.username"></j-input>
            </a-form-item>
          </a-col>

          <a-col :md="5" :sm="12">
            <a-form-item label="设备名称">
              <!--<a-input placeholder="请输入账号查询" v-model="queryParam.username"></a-input>-->
              <j-input placeholder="输入设备名称" v-model="queryParam.username"></j-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
          <a-col :md="5" :sm="12">
            <a-form-item label="规格">
              <!--<a-input placeholder="请输入账号查询" v-model="queryParam.username"></a-input>-->
              <j-input placeholder="输入规格" v-model="queryParam.username"></j-input>
            </a-form-item>
          </a-col>

            <a-col :md="5" :sm="8">
              <a-form-item label="生产商">
                <a-input placeholder="请输入生产商" v-model="queryParam.realname"></a-input>
              </a-form-item>
            </a-col>

            <a-col :md="5" :sm="8">
              <a-form-item label="出货人">
                <a-input placeholder="请输入出货人" v-model="queryParam.phone"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="5" :sm="8">
              <a-form-item label="出售日期">
                <a-date-picker show-time placeholder="出售日期" @change="onChange" @ok="onOk" />
              </a-form-item>
            </a-col>
          </template>

          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <a-col>
      <a-table
        ref="table"
        bordered
        size="middle"
        rowKey="userId"
        :pagination="ipagination"
        :columns="columns"
        :dataSource="dataSource"
        :loading="loading"
        @change="handleTableChange">
       <span slot="action" slot-scope="text, record">
            <a @click="handleOpen(record)">账号信息</a>
       </span>
      </a-table>
    </a-col>
    <!--  账号信息 modal  -->
    <a-modal v-model="visible2" :width="1300" title="账号信息" @ok="handleOk2">
      <a-col>
        <a-table
          ref="table"
          bordered
          size="middle"
          rowKey="userId"
          :pagination="ipagination"
          :columns="columns_zhanghao"
          :dataSource="dataSource"
          :loading="loading"
          @change="handleTableChange">
       <span slot="action" slot-scope="text, record">
            <a @click="handleOpen_zhanghao(record)">编辑</a>
       </span>
        </a-table>
      </a-col>
    </a-modal>
    <!--  账号信息 modal  -->
    <a-modal v-model="visible3" :width="700" title="修改账号信息" @ok="handleOk3">
      <a-form layout="inline" :form="form">
      <a-col>
        <a-row style="width: 100%;padding-top: 20px;">
          <a-col :span="18">
            <a-form-item label="肤质检测仪类型">
              <j-select-multiple style="width: 200px" v-model="jselectMultiple.value" :options="jselectMultiple.options"/>
            </a-form-item>
          </a-col>
        </a-row>

        <a-row style="width: 100%;padding-top: 20px;">
          <a-col :span="18">
            <a-form-item  label="账号" hasFeedback>
              <a-input style="width: 270px" placeholder="请输入登录账号" v-decorator="['gateway', {}]" />
            </a-form-item>
          </a-col>
        </a-row>
        <a-row style="width: 100%;padding-top: 20px;">
          <a-col :span="24">
            <a-form-item  label="密码" hasFeedback>
              <a-input style="width: 270px" placeholder="请输入登录密码" v-decorator="['gateway', {}]" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-col>
      </a-form>
    </a-modal>
  </a-card>
</template>

<script>
import { getAction } from '@api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import JSelectMultiple from '@/components/jeecg/JSelectMultiple'

export default {
  name: 'equipmentModalB',
  mixins: [JeecgListMixin],
  components: {
    JSelectMultiple,
  },
  props: ['value'],
  data() {
    return {
      description: '用户信息',
      cardLoading: true,
      visible: false,
      visible2: false,
      visible3: false,
      indexStyle:1,
      // 出售设备 数据
      jselectMultiple: {
        options: [
          { text: '字符串', value: 'String' },
          { text: '整数型', value: 'Integer' },
          { text: '浮点型', value: 'Double' },
          { text: '布尔型', value: 'Boolean' }
        ],
        value: 'Integer,Boolean'
      },
      number_chushou:1,
      positionInfo: {},
      columns:[
        {
          title: '#',
          key: 'rowIndex',
          dataIndex: '',
          width: 60,
          align: 'center',
          customRender: (t, r, i) => parseInt(i) + 1
        },
        {
          title: '姓名',
          width: '15%',
          align: 'center',
          dataIndex: 'realname'
        },
        {
          title: '工号',
          width: '',
          align: 'center',
          dataIndex: 'workNo'
        },
        {
          title: '部门',
          width: '',
          align: 'center',
          dataIndex: 'departName'
        },
        {
          title: '职务',
          width: '',
          align: 'center',
          dataIndex: 'post',
          customRender: (text) => (text || '').split(',').map(t => this.positionInfo[t] ? this.positionInfo[t] : t).join(',')
        },
        {
          title: '手机',
          width: '',
          align: 'center',
          dataIndex: 'telephone'
        },
        // {
        //   title: '手机号',
        //   width: '12%',
        //   align: 'center',
        //   dataIndex: 'phone'
        // },
        {
          title: '公司邮箱',
          width: '',
          align: 'center',
          dataIndex: 'email'
        } ,{
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      columns_zhanghao: [
        {
          title: '所属店铺',
          align: 'center',
          dataIndex: 'realname'
        },
        {
          title: '设备账号',
          width: '',
          align: 'center',
          dataIndex: 'workNo'
        },
        {
          title: '账号编码',
          width: '',
          align: 'center',
          dataIndex: 'departName'
        },
        {
          title: '肤质检测仪编号',
          width: '',
          align: 'center',
          dataIndex: 'post',
        },
        {
          title: '设备开通时间',
          width: '',
          align: 'center',
          dataIndex: 'telephone'
        },

        {
          title: '最近登录时间',
          width: '',
          align: 'center',
          dataIndex: 'email'
        } ,{
          title: '所在地',
          width: '',
          align: 'center',
          dataIndex: 'phone'
        },{
          title: '使用时长',
          width: '',
          align: 'center',
          dataIndex: 'phone'
        },{
          title: '状态',
          width: '',
          align: 'center',
          dataIndex: 'phone'
        }
        ,{
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],

      url: {
        list: '/sys/user/queryByOrgCodeForAddressList',
        listByPosition: '/sys/position/list'
      }
    }
  },
  watch: {
    value: {
      immediate: true,
      handler(orgCode) {
        this.dataSource = []
        this.loadData(1, orgCode)
      }
    },
  },
  created() {
    this.queryPositionInfo()
  },
  methods: {

    loadData(pageNum, orgCode) {
      this.loading = true
      if (pageNum === 1) {
        this.ipagination.current = 1
      }
      // update-begin- --- author:wangshuai ------ date:20200102 ---- for:传过来的部门编码为空全查
      if (!orgCode) {
        getAction(this.url.list, {
          ...this.getQueryParams()
        }).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records
            this.ipagination.total = res.result.total
          }
        }).finally(() => {
          this.loading = false
          this.cardLoading = false
        })
        // update-end- --- author:wangshuai ------ date:20200102 ---- for:传过来的部门编码为空全查
      }else{
        //加载数据 若传入参数1则加载第一页的内容
        getAction(this.url.list, {
          orgCode,
          ...this.getQueryParams()
        }).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records
            this.ipagination.total = res.result.total
          }
        }).finally(() => {
          this.loading = false
          this.cardLoading = false
        })
      }
    },
//筛选 选择日期
    onChange(value, dateString) {
      console.log('Selected Time: ', value);
      console.log('Formatted Selected Time: ', dateString);
    },
// 入库
    ruku() {
      this.visible = true;
    },
    handleOk(e) {
      console.log(e);
      this.visible = false;
    },
// 入库结束

//账号信息
    handleOpen(){
      this.visible2 = true;
    },
    handleOk2(e) {
      console.log(e);
      this.visible2 = false;
    },
    onChange_chushou(number_chushou) {
      console.log('changed', number_chushou);
    },
    handleOpen_zhanghao(){
      this.visible3 = true;
    },
    handleOk3(e) {
      console.log(e);
      this.visible3 = false;
    },

    searchQuery() {
      this.loadData(1, this.value)
    },
    searchReset() {
      this.queryParam = {}
      this.loadData(1, this.value)
    },

    handleTableChange(pagination, filters, sorter) {
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field
        this.isorter.order = 'ascend' === sorter.order ? 'asc' : 'desc'
      }
      this.ipagination = pagination
      this.loadData(null, this.value)
    },

    // 查询职务信息
    queryPositionInfo() {
      getAction(this.url.listByPosition, { pageSize: 99999 }).then(res => {
        if (res.success) {
          let positionInfo = {}
          res.result.records.forEach(record => {
            positionInfo[record['code']] = record['name']
          })
          this.positionInfo = positionInfo
        }
      })
    }

  }
}
</script>
<style>
.j-address-list-right-card-box .ant-table-placeholder {
  min-height: 46px;
}
</style>
<style scoped>
.j-address-list-right-card-box {
  height: 100%;
  min-height: 300px;
}
</style>